using UnityEngine;

public class Baddie : MonoBehaviour
{
    [SerializeField] private float piggieHealth;
    [SerializeField] private GameObject piggieDeathParticle;
    private readonly float injuryThreshold = 1f;

    private void DamageHealth(float damageAmount)
    {
        piggieHealth -= damageAmount;

        if (piggieHealth <= 0)
        {
            Instantiate(piggieDeathParticle, transform.position, Quaternion.identity);
            // 删除小猪合集与游戏对象
            GameManager.instance.DestroyPiggie(this);
        }
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        // 伤害检测
        float velocity = collision.relativeVelocity.magnitude;
        if (velocity >= injuryThreshold)
        {
            DamageHealth(velocity);
        }
    }
}
